//
//  HeartRateModel.m
//  uteped_sdk
//
//  Created by mateng on 2024/2/28.
//

#import "HeartRateModel.h"

@implementation HeartRateModel

- (void)from:(UTEModelMotionFrame*)data frameItem:(UTEModelMotionFrameItem*)frameItem {
    UTEModelMotionFrameItemContent *content = frameItem.content;
    self.time = [DateUtils timeToInt:frameItem.time fmt:FMT_TIME_SECS];
    self.startTime = self.time;
    self.restingHeartRate = content.restingHeartRate;
    self.dynamicHeartRate = content.dynamicHeartRate;
    self.heartRateMax = content.heartRateMax;
    self.heartRateMin = content.heartRateMin;
    self.heartRateAvg = content.heartRateAve;
    self.rate = content.heartRateAve;//iOS 缺失
    
    self.calendarTime = [DateUtils timeStampToString:self.startTime fmt:FMT_TIME_CLANDER_TIME];
    self.calendar = [DateUtils timeStampToString:self.startTime fmt:FMT_TIME_CLANDER];
    
    [self.storeData setObject:@(self.time) forKey:@"time"];
    [self.storeData setObject:@(self.startTime) forKey:@"start_time"];
    [self.storeData setObject:@(self.restingHeartRate) forKey:@"resting_heart_rate"];
    [self.storeData setObject:@(self.dynamicHeartRate) forKey:@"dynamic_heart_rate"];
    [self.storeData setObject:@(self.rate) forKey:@"rate"];
    [self.storeData setObject:@(self.heartRateMax) forKey:@"heart_rate_max"];
    [self.storeData setObject:@(self.heartRateMin) forKey:@"heart_rate_min"];
    [self.storeData setObject:@(self.heartRateAvg) forKey:@"heart_rate_avg"];
    [self.storeData setObject:self.calendarTime forKey:@"calendar_time"];
    [self.storeData setObject:self.calendar forKey:@"calendar"];
}

- (BOOL)validateValue {
    return self.heartRateAvg > 0 && self.heartRateMax > 0 && self.heartRateMin > 0;
}

@end
